因為要用到git的套件,所以要先看看你虛擬機上的git版本是否最新,如果不是請在root模式下:
# yum update nss curl\
參考於:git clone 報錯 incompatible or unsupported protocol version處理方法。 先git clone google-authenticator-libpam到你虛擬機的桌面安裝Development Tools。
從github下載安裝google-authenticator
# git clone https://github.com/google/google-authenticator-libpam.git
先安裝編譯所需套件
# yum groupinstall "Development Tools"
進行編譯
# cd google-authenticator-libpam
# ./bootstrap.sh
# ./configure
# make && make install
如果出現錯誤訊息,無法找到PAM library or the PAM header檔案,就先安裝pam-devel套件後,再下./configure指令。
# yum install pam-devel
# ./configure
# make && make install
然後把pam_google_authenticator.so移動或複製到/usr/lib64/security/,通常pam_google_authenticator.so會在/usr/local/lib/security/目錄中,你也可先下指令找尋。
# find / -name pam_google_authenticator.so -type f
# mv /usr/local/lib/security/pam_google_authenticator.so /usr/lib64/security/
# gedit /etc/pam.d/sshd
把以下內容加入在最後一行(因為不一定所有用戶都有設定密鑰,為了要讓他們也能登入,就要在模組命令行中傳遞"nullok"選項)
auth required pam_google_authenticator.so nullok
然後把sshd_config檔裡的驗證回應改成yes。
# gedit /etc/ssh/sshd_config
驗證回應改成yes(把驗證回應選項開啟)。
ChallengeResponseAuthentication yes
重啟SSH Service。
#systemctl restart sshd
執行google-authenticator後會出現QRcode,然後在手機下載google-authenticator,手機開啟google-authenticator後,會請你掃碼或輸入金鑰,之後你在遠端登入用SSH協定時,必須再輸入手機二次驗證碼,還有個重點是在QRcode下方有五行數字,那五個字串是你無法正常驗證時,用來當萬能鑰匙的。
# google-authenticator
全部選項都設YES